package offer.algorithm;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/27 16:03
 */
public class SubIsNum41 {

    public static void findSubIsNum(int[] array, int num) {
        int index = array.length - 1;
        for (; index > 0; --index) {
            if (array[ index ] <= num)
                break;
        }
        int start = 0, end = index;
        int temp;
        while (start < index) {
            temp = array[ start ] + array[ end ];
            if (temp == num) {
                System.out.println("Start index " + start + " : " + "End index " + end);
                return;
            } else if (temp > num) {
                end--;
            } else {
                start++;
            }
        }
        System.out.println("There isn't two num which sum is num!!!");
    }


    public static void findSequenceNumK(int k) {
        int start = 0, index = 0, end = (k >> 1) + 2, sum = 0;
        while (index <= end) {
            if (sum == k) {
                System.out.println("------找到序列-------");
                for (int i = start; i < index; i++) {
                    System.out.print(i + " ");
                }
                System.out.println();
                sum -= start;
                start++;
            } else if (sum < k) {
                sum += index;
                index++;
            } else {
                sum -= start;
                start++;
            }
        }
    }

}
